package com.cl.blog.common;

import lombok.Data;

import java.io.Serializable;

/**
 * @Author 付
 * @Date 2024-02-24 13:51
 * @Version 1.0
 * @description 消息封装类，用来封装从后端返回到前端的结果集
 * @since 1.0
 */
@Data
public class Result implements Serializable {
	private int code;
	private Object data;
	private String msg;

	/**
	 * 数据获取成功的时候，执行的返回方法
	 * @param data 返回的数据
	 * @return
	 */
	public static Result success(Object data){
		Result result = new Result();
		result.setCode(200);
		result.setData(data);
		result.setMsg("数据获取成功");
		return result;
	}

	/**
	 * 对数据进行修改时，执行的操作
	 * @return
	 */
	public  static Result success(){
		Result result = new Result();
		result.setMsg("操作成功");
		result.setCode(200);
		return result;
	}

	/**
	 * 出现错误时，执行的操作
	 * @param msg 返回的错误信息
	 * @return
	 */
	public static Result error(String msg){
		Result result = new Result();
		result.setCode(400);
		result.setMsg(msg);
		return result;
	}

	public static Result error(String msg,int code){
		Result result = new Result();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}
}

